﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MINERP.BLL.PrintManage;

namespace MINERP.Statistics.Forms
{
    public partial class FrmPrintPaper : Form
    {
        PaperWasteRecordBLL bll = new PaperWasteRecordBLL();
        private static FrmPrintPaper _instance = null;
        private  FrmPrintPaper()
        {

            InitializeComponent();
        }

        public static FrmPrintPaper GetInstance
        {
            get
            {
                _instance = new FrmPrintPaper();
                return _instance;
            }
        }
        private void simpleButtonOk_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            simpleButtonOk.Enabled = false;

            try
            {
                reportPrintPaper.Preview = previewControl1;
                reportPrintPaper.Load(Application.StartupPath + "\\PrintPaper.frx");
                reportPrintPaper.RegisterData(bll.GetPrintPaperUsage(cmbPrinter.SelectedText, dateEditStartTime.DateTime, dateEditEndTime.DateTime), "paperUse");
                previewControl1.Refresh();
                previewControl1.Show();
                reportPrintPaper.Show();
            }
            finally
            {
                simpleButtonOk.Enabled = true;
                this.Cursor = Cursors.Default;
            }
        }

        private void LinkPrinter()
        {
            cmbPrinter.Properties.Items.Clear();
            foreach (var item in bll.GetPrinterList())
            {
                cmbPrinter.Properties.Items.Add(item.PName);
            }
        }

        private void FrmPrintPaper_FormClosing(object sender, FormClosingEventArgs e)
        {
            _instance = null;
        }

        private void FrmPrintPaper_Load(object sender, EventArgs e)
        {
            LinkPrinter();
            dateEditStartTime.DateTime = DateTime.Now.Date;
            dateEditEndTime.DateTime = DateTime.Now;
        }
    }
}
